package com.edu.app.util.json;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;


public class JsonUtil {
    public static ObjectMapper mapper = new ObjectMapper();
    public static String toJson(Object jobj) throws JsonProcessingException
    {
        String jsonString = mapper.writeValueAsString(jobj);
        return jsonString;
    }


    public static <T extends Object> T fromJson(String json,Class<T> type) throws java.io.IOException
    {

        T obj =  mapper.readValue(json, type  );
        return  obj;
    }

    public static JsonNode toJsonNode(String json) throws java.io.IOException{
        JsonNode node = mapper.readTree(json);
        return node;
    }

}
